
%%% Weighting the Evidence: A Rank-Dependent Model of Outdoor Recreation, June 2024
%%% This function evaluates the rank-dependent utility for the Tversky and Kahneman weighting function, given parameters and a probability distribution determining the ranks

function v=RDU_tk(parameters,baglimit,nbinR,nbinP,sf_r,bsb_k,bsb_r,scup_c,c)

n=baglimit+1; %number of ranked outcomes;
u=zeros(1,n);
P=zeros(1,n);
pi=zeros(1,n);

for i=1:n
u(i)=(1-exp(-parameters(6)*(parameters(2)*(i-1)/100+parameters(1)*sf_r/100+parameters(4)*bsb_k/100+parameters(3)*bsb_r/100+parameters(5)*scup_c)))/parameters(6);
if i>1
P(i)=1-nbincdf(i-2,nbinR,nbinP);
end
end

P(1)=1;
P(n+1)=0;
for i=1:n
pi(i)=W_tk(parameters(16),P(i))-W_tk(parameters(16),P(i+1));
end
v=pi*u'+parameters(7)*c;

end